<?php
    include 'eng.php';
    include 'connect.php';
    include '../../functions.php';

    $flag=0;
    if(isset ($_COOKIE['Name4']) && isset ($_COOKIE['Pass4']))
    {
        $_POST['name']=$_COOKIE['Name4'];
        $_POST['password']=$_COOKIE['Pass4'];
        $_POST['sendData']='send';
    }
    if(isset($_POST['sendData']))
    {
        $name=trim($_POST['name']);
        $pass=trim($_POST['password']);
        $age=trim($_POST['age']);
        $email=trim($_POST['email']);
            if(!preg_match("/[a-z A-z]/",$name))
            {
                 echo "error at name<br>";
            }
            elseif(!preg_match("/[a-z0-9]*@{1}[a-z0-9]*\.[a-z0-9]/i",$email))
            {
                echo "error at email<br>";
            }
            elseif(empty($pass) ||  strlen($pass)<3)
            {
                echo "error at password must be more than 3 letters<br>";
            }
            else
            {
                // check name
                $resulSet=mysql_query("select id from `users` where `name`='$name'");
                $result=mysql_fetch_array($resulSet);
                if(!empty($result['id']))
                {
                    echo "this name $name already exist";
                }
                else
                {

	    if(isset($_POST['rem']))
	    {
		setcookie("Name4", $name, time()+3600);
		setcookie("Pass4",$pass, time()+3600);

	    }
                    $pass=md5($pass);
                    if(mysql_query("insert into `users` set `name`='$name',`age`='$age',`pass`='$pass',`email`='$email'")){
                       echo "gooooood";
                       $flag=1;
                        header("refresh: 1; login.php");
                    }
                }
            }
    }
    if($flag==0)
    {
?>
<script src="jquery-1.5.1.js"></script>
<script src="js/regester.js"></script>
<link rel="stylesheet" href="css/style.css">

    <form method="post">
    <?php echo NAME ?>: <input class="valid" id="name" type="text" name="name" /><span class="error" id="ername">error at name</span><br>
    <?php echo PASSWORD ?>: <input class="valid" id="pass" type="password" name="password" /><span class="error" id="erpass">error at password</span><br>
    <?php echo AGE ?>: <input class="valid" type="text" name="age" /> <br>
    <?php echo EMAIL ?>: <input class="valid" id="email" type="text" name="email" /><span class="error" id="ermail">error at email</span><br>
    <input id="button" type="submit" name="sendData" value="ok" />
    </form>

<?php

    }
?>
